Unable to preview attachments using the new file preview in a page after upgrade to 5.7 and later versions
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Problem
After upgrading to Confluence 5.7 and above, attachment link in a page does not open a preview of the file.
The following message is displayed:
We can't preview this file
You'll have to download the file to view it
Observed issues are with PDF type attachments, JPEG and PNG images
The following appears in the atlassian-confluence.log
2015-02-17 07:48:56,813 ERROR [conversion-thread-3-internal] [conversion.impl.runnable.ConversionRunnable] doWork Format cannot be converted
-- referer: http://testserver:8090/display/TS/Incident+and+Problemmanagement?preview=/17663912/17795772/How%20To%20Code%20In%20Java.pdf | url: /rest/documentConversion/0.1/conversion/convert/17795772/1 | userName: tester
Diagnosis
- A newly inserted attachments can be previewed by clicking on its link.
- The file itself is downloadable
Diagnostic Steps
- Try to replicate this in all browsers
- Navigate to an existing page that has PDF Attachment link embedded
- Click on the PDF link
- Generate a HAR file and check when clicking on the old attachment link. Instead of getting the 'Resource', a 'HEAD' is returned when the command "byAttachmentIds" and "minusAttachmentIds" are sent
- Run the following SQL query:
- If there are rows returned, please continue to the Resolution section. If it returns empty result, you are not being affected by the issue in this article. Please contact Atlassian Support to assist you.
- If there are rows returned, please continue to the Resolution section. If it returns empty result, you are not being affected by the issue in this article. Please contact Atlassian Support to assist you.
SELECT * FROM CONTENTPROPERTIES WHERE PROPERTYNAME = 'MEDIA_TYPE' AND STRINGVAL LIKE '%pdf%';
SELECT * FROM CONTENTPROPERTIES WHERE PROPERTYNAME = 'MEDIA_TYPE' AND STRINGVAL LIKE '%pjpeg%';
SELECT * FROM CONTENTPROPERTIES WHERE PROPERTYNAME = 'MEDIA_TYPE' AND STRINGVAL LIKE '%x-png%';
Cause
The Content Type of the attachments are wrong
- PDF Attachment isnot '
application/pdf
' as how it should be, instead the Content Type is either in one of this format; 'pdf', 'image/pdf
' or 'application/x-pdf
'. - JPEG images isnot 'image/jpeg' as how it should be, instead the Content Type is either in one of this format; 'image/pjpeg'.
- PNG images isnot 'image/png' as how it should be, instead the Content Type is either in one of this format; 'image/x-png'.
These values are already invalid before performing the upgrade.
For more information please refer to CONF-36666 - Getting issue details... STATUS .
Resolution
Run the following SQL query:
For issues with PDF:
UPDATE contentproperties SET STRINGVAL = 'application/pdf' WHERE PROPERTYNAME = 'MEDIA_TYPE' AND STRINGVAL LIKE '%pdf%';
For issues with JPEG images:
UPDATE contentproperties SET stringval = replace(stringval, 'image/pjpeg', 'image/jpeg') WHERE PROPERTYNAME = 'MEDIA_TYPE';
For issues with PNG images:
UPDATE contentproperties SET stringval = replace(stringval, 'image/x-png', 'image/png') WHERE PROPERTYNAME = 'MEDIA_TYPE';
Flush your Confluence caches by navigating through Confluence Administration Panel >> Cache Management >> Flush All.
Always backup your data before performing any modifications to the database.